<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <title>新建请假</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link rel="stylesheet" href="/layui/css/layui.css" media="all" />
    <style type="text/css">
        .layui-form-item .layui-inline{ width:33.333%; float:left; margin-right:0; }
        @media(max-width:1240px){
            .layui-form-item .layui-inline{ width:100%; float:none; }
        }
        .layui-form-item .role-box {
            position: relative;
        }
        .layui-form-item .role-box .jq-role-inline {
            height: 100%;
            overflow: auto;
        }

    </style>
</head>
<body class="childrenBody">
<form class="layui-form" style="width:80%;">
    <div class="layui-form-item">
        <fieldset class="layui-elem-field layui-field-title" style="margin-top: 10px;">
            <legend style="font-size:16px;">请假信息</legend>
        </fieldset>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label"><span class="x-red">*</span>开始时间</label>
        <div class="layui-input-block " >
            <input type="text"  id="beginTime" name="beginTime"  lay-verify="beginTime"  placeholder="yyyy-MM-dd"
            autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label"><span class="x-red">*</span>结束时间</label>
        <div class="layui-input-block">
            <input type="text" id="endTime" name="endTime" lay-verify="endTime"  placeholder="yyyy-MM-dd"  autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label"><span class="x-red">*</span>原因</label>
        <div class="layui-input-block">
            <textarea name="reason" class="layui-textarea" placeholder="原因"></textarea>
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" lay-submit="" lay-filter="addLeave">立即提交</button>
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
    </div>
</form>
<script type="text/javascript" src="/layui/layui.js"></script>
<script>
    layui.config({
        base: '/js/common/' //假设这是你存放拓展模块的根目录
    }).use(['form','jquery','layer','common','laydate'],function(){
        var form = layui.form,
            $    = layui.jquery,
            common = layui.common,
            laydate = layui.laydate,
            layer = layui.layer;
        form.on('select(type)', function (data) {   //选择移交单位 赋值给input框
            $("#HandoverCompany").val(data.value);
            $("#type").next().find("dl").css({ "display": "none" });
            form.render();
        });
        window.search = function () {
            var value = $("#HandoverCompany").val();
            $("#type").val(value);
            form.render();
            $("#type").next().find("dl").css({ "display": "block" });
            var dl = $("#type").next().find("dl").children();
            var j = -1;
            for (var i = 0; i < dl.length; i++) {
                if (dl[i].innerHTML.indexOf(value) <= -1) {
                    dl[i].style.display = "none";
                    j++;
                }
                if (j == dl.length-1) {
                    $("#type").next().find("dl").css({ "display": "none" });
                }
            }

        };
        var d = new Date();
        var day=d.getFullYear()+"-"+(parseInt(d.getMonth())+1)+'-'+d.getDate();
        var a = laydate.render({
            elem: '#beginTime',
            min:day,
            done: function(value, date, endDate) {
                b.config.min = {
                    year: date.year,
                    month: date.month - 1,
                    date: date.date,
                    hours: date.hours,
                    minutes: date.minutes,
                    seconds: date.seconds
                }
            }
        });
        var b = laydate.render({
            elem: '#endTime',
        });
        form.on("submit(addLeave)",function(data){
            var saveLoading = top.layer.msg('数据提交中，请稍候',{icon: 16,time:false,shade:0.8});
            $.post("addLeave",data.field,function(res){
                if(res.success){
                    top.layer.close(saveLoading);
                    common.cmsLaySucMsg("添加成功！");
                    var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                    parent.layer.close(index); //再执行关闭                        //刷新父页面
                    parent.location.reload();
                }else{
                    top.layer.close(saveLoading);
                    common.cmsLayErrorMsg(res.message);
                }
            });
            return false;
        });

    });
</script>
</body>
</html>